From 3a7d1756350b690277ef95bcf96e0af1a8bb5c1d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 25 Mar 2015 10:20:50 -0700 Subject: [PATCH] Only disallow hyphens in lib target names Examples, tests, binaries, etc, are all allowed to have hyphens (cargo does some renaming internally). Close #1450 --- src/cargo/util/toml.rs | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 23d255b79..debe90e37 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -396,7 +396,7 @@ impl TomlManifest { _ => {} } try!(libs.as_slice().iter().map(|t| { - try!(validate_target_name(t)); + try!(validate_library_name(t)); Ok(if layout.lib.is_some() && t.path.is_none() { TomlTarget { path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())), @@ -414,48 +414,36 @@ impl TomlManifest { Some(ref bins) => { let bin = layout.main(); - try!(bins.iter().map(|t| { - try!(validate_target_name(t)); - Ok(if bin.is_some() && t.path.is_none() { + bins.iter().map(|t| { + if bin.is_some() && t.path.is_none() { TomlTarget { path: bin.as_ref().map(|&p| PathValue::Path(p.clone())), .. t.clone() } } else { t.clone() - }) - }).collect::>>()) + } + }).collect() } None => inferred_bin_targets(&project.name, layout) }; let examples = match self.example { - Some(ref examples) => { - for example in examples { - try!(validate_target_name(example)); - } - examples.clone() - } + Some(ref examples) => examples.clone(), None => inferred_example_targets(layout), }; let tests = match self.test { - Some(ref tests) => { - for test in tests { - try!(validate_target_name(test)); - } - tests.clone() - } + Some(ref tests) => tests.clone(), None => inferred_test_targets(layout), }; let benches = if self.bench.is_none() || self.bench.as_ref().unwrap().is_empty() { inferred_bench_targets(layout) } else { - try!(self.bench.as_ref().unwrap().iter().map(|t| { - try!(validate_target_name(t)); - Ok(t.clone()) - }).collect::>>()) + self.bench.as_ref().unwrap().iter().map(|t| { + t.clone() + }).collect() }; // processing the custom build script @@ -544,9 +532,9 @@ impl TomlManifest { } } -fn validate_target_name(target: &TomlTarget) -> CargoResult<()> { +fn validate_library_name(target: &TomlTarget) -> CargoResult<()> { if target.name.contains("-") { - Err(human(format!("target names cannot contain hyphens: {}", + Err(human(format!("library target names cannot contain hyphens: {}", target.name))) } else { Ok(()) -- 2.30.2